package com.zhiyou100.video.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import com.zhiyou100.video.dao.VideoDao;
import com.zhiyou100.video.model.Course;
import com.zhiyou100.video.model.Speaker;
import com.zhiyou100.video.model.Video;
@SuppressWarnings("unchecked")
public class VideoDaoImpl extends HibernateDaoSupport implements VideoDao {

	@Override
	public List<Speaker> selectSpeaker() {
		DetachedCriteria criteria = DetachedCriteria.forClass(Speaker.class);
		return (List<Speaker>) getHibernateTemplate().findByCriteria(criteria);
	}
	@Override
	public List<Video> selectVideo(DetachedCriteria video, Integer currentpage) {
		return (List<Video>) getHibernateTemplate().findByCriteria(video,(currentpage-1)*5,5);
				
	}
	@Override
	public Integer selectCount(DetachedCriteria video) {
		return getHibernateTemplate().findByCriteria(video).size();
	}
	@Override
	public List<Course> selectCourse() {
		DetachedCriteria dc = DetachedCriteria.forClass(Course.class);
		return (List<Course>) getHibernateTemplate().findByCriteria(dc);
	}
	@Override
	public void addVideo(Video video) {
			getHibernateTemplate().saveOrUpdate(video);
	}
	@Override
	public void deleteVideo(Integer did) {
		Video video = getHibernateTemplate().get(Video.class, did);
		getHibernateTemplate().delete(video);
		
	}
	@Override
	public Video selectVideol(Integer id) {
		
		return getHibernateTemplate().get(Video.class, id);
	}
	@Override
	public List<Video> selectVideok(DetachedCriteria dc) {
		return (List<Video>) getHibernateTemplate().findByCriteria(dc);
	}

}
